/*
 * @lc app=leetcode.cn id=404 lang=cpp
 *
 * [404] 左叶子之和
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:

/*
    int Sum(TreeNode * root,int &val)
    {
        if(root == NULL)
            return 0;
        if(root->left != NULL && root->left->left == NULL && root->left->right == NULL)
            val += root->left->val;
        Sum(root->left,val);
        Sum(root->right,val);
        return val;
    }



    int sumOfLeftLeaves(TreeNode* root) {
        int val = 0;
        Sum(root,val);
        return val;
    }

*/
    int sumOfLeftLeaves(TreeNode* root) {
        
        if(root == NULL)
            return 0;
        int res = 0;
        if(root->left != NULL && root->left->left == NULL && root->left->right == NULL)
            res += root->left->val;
        return res + sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);
    }


};
// @lc code=end

